#include "stdio.h"
#include "syscall.h"
#include "string.h"
int main(int argc, char** argv) {
   int arg_idx = 0;
   printf("argc = %d\n", argc);
   while(arg_idx < argc) {
      printf("argv[%d] is %s\n", arg_idx, argv[arg_idx]);
      arg_idx++;
   }
   int pid = fork();
   if (pid) {
      int delay = 1000000;
      while(delay--);
      printf("\n      I`m father prog, my pid:%d, I will show process list\n", getpid()); 
      ps();
   } 
   else {
//      int temp_buf[128] = {0};
//	  char *abs_path = (char *) temp_buf;  // gcc 编译出来也能正常运行.
	  char abs_path[512] = {0};  // gcc-3.4 编译的程序能正常运行, gcc 编译的不能正常运行.
      printf("\n   I`m child prog, my pid:%d, I will exec %s right now\n", getpid(), argv[1]);
#if 1	  
		if (argv[1][0] != '/') {
		getcwd(abs_path, 512);
		strcat(abs_path, "/");
		strcat(abs_path, argv[1]);
		execv(abs_path, argv);
		} else {
		execv(argv[1], argv);	 
		}
#endif
   }
   while(1);
   return 0;
}
